// pages/user/Ioboundorders/fillInbound/fillInbound.js
Page({  
    data: {  
      boardTypes: ["板子A", "板子B"],  
      boardMaterials: ["基材A", "基材B"],  
      boardDensities: ["低密度板", "中密度板", "高密度板"],  
      hardwareSpecs: ["2寸*1.5", "2.5寸*1.5"],  
      hardwareBrands: ["品牌A", "品牌B"],  
      boardTypeIndex: 0,  
      boardMaterialIndex: 0,  
      boardDensityIndex: 0,  
      hardwareSpecIndex: 0,  
      hardwareBrandIndex: 0,  
      boardColor: '',  
      boardQuantity: '',  
      hardwareQuantity: '',  
      specialFunction: '',  
    },  
    onBoardTypeChange: function(e) {  
        this.setData({ boardTypeIndex: e.detail.value });  
      },  
      onBoardColorInput: function(e) {  
        this.setData({ boardColor: e.detail.value });  
      },  
      onBoardMaterialChange: function(e) {  
        this.setData({ boardMaterialIndex: e.detail.value });  
      },  
      onBoardDensityChange: function(e) {  
        this.setData({ boardDensityIndex: e.detail.value });  
      },  
      onBoardQuantityInput: function(e) {  
        const quantity = e.detail.value;  
        if (quantity >= 0) {  
          this.setData({ boardQuantity: quantity });  
        } else {  
          wx.showToast({  
            title: '板子数量不能为负数',  
            icon: 'none',  
            duration: 2000,  
          });  
        }  
      },  
      onHardwareSpecChange: function(e) {  
        this.setData({ hardwareSpecIndex: e.detail.value });  
      },  
      onHardwareBrandChange: function(e) {  
        this.setData({ hardwareBrandIndex: e.detail.value });  
      },  
      onHardwareQuantityInput: function(e) {  
        const quantity = e.detail.value;  
        if (quantity >= 0) {  
          this.setData({ hardwareQuantity: quantity });  
        } else {  
          wx.showToast({  
            title: '五金数量不能为负数',  
            icon: 'none',  
            duration: 2000,  
          });  
        }  
      },  
      onSpecialFunctionInput: function(e) {  
        this.setData({ specialFunction: e.detail.value });  
      },  

    saveData: function() {  
        const dataToSave = {  
        boardType: this.data.boardTypes[this.data.boardTypeIndex],  
        boardColor: this.data.boardColor,  
        boardMaterial: this.data.boardMaterials[this.data.boardMaterialIndex],  
        boardDensity: this.data.boardDensities[this.data.boardDensityIndex],  
        boardQuantity: this.data.boardQuantity,  
        hardwareSpec: this.data.hardwareSpecs[this.data.hardwareSpecIndex],  
        hardwareBrand: this.data.hardwareBrands[this.data.hardwareBrandIndex],  
        hardwareQuantity: this.data.hardwareQuantity,  
        specialFunction: this.data.specialFunction,  
      };  
        

      // 使用微信小程序的存储API保存数据  
      // wx.setStorage({  
      //   key: 'inventoryData',  
      //   data: dataToSave,  
      //   success: function() {  
      //     wx.showToast({  
      //       title: '数据保存成功',   
      //       icon: 'success',  
      //       duration: 2000,  
      //     });  
      //   },  
      //   fail: function() {  
      //     wx.showToast({  
      //       title: '数据保存失败',  
      //       icon: 'none',  
      //       duration: 2000,  
      //     });  
      //   }  
      // });  

      
      const uniqueKey = `inventoryData_${Date.now()}`;  
      try {  
        // 将新的表单数据存到storage中，使用唯一的key  
        wx.setStorageSync(uniqueKey, dataToSave);  
      } catch (e) {  
        // 处理错误  
        console.error('Error storing inventory data:', e);  
      }
    }, 
  });